{literal}
<h2>Annotation</h2>
@orm changelog $className <br>
<br />
Change log logs all changes to record object.<br />
This plugin creates for each change one entry. Meaning that each change is one row in database.<br />
<br />
Also check <b>History</b> plugin.<br />
<br />
<br />
If change log property is in parent class then it will also log all property  actions that belong to child classes. (That extend to it.)<br />
<br />
<h2>Sample</h2>
<br />
<pre class="code">
&lt;?php
class Item extends DomArObject {

	/**
	* @orm text
	*/
	public $title;
	/**
	* @orm longtext
	*/
	public $description;
	/**
	 * @orm has parent User inverse items
	 */
	public $user;
	/**
	 * @orm changelog DomArChangeLogItem
	 */
	public $changelog;
}

class User extends DomArObject {
	
	/**
	* @orm text
	*/
	public $username;
	/**
	 * @orm has many Item inverse user
	 */
	public $items;
}
?&gt;
</pre>




<h2>Creating some sample data</h2>
<pre class="code">
&lt;?php
$u1 = new User();
$u1->username = 'Balduran';
		
$u2 = new User();
$u2->username = 'Oliver';
		
$a = new Item();
$a->title  = 'Hello';
$a->description = 'World';
$a->user = $u1;

$a->save();
$u2->save();
?&gt;
</pre>




<h2>Working with history</h2>
<pre class="code">
&lt;?php

$a->title = 'New title';
$a->description  = 'New description';
$a->user = $u2;
$a->save();

$log = $a->changeLog->query()->orderBy('t.id')->commit()->toArray();
echo $log[0]->value; // Hello
echo $log[1]->value; // World
echo $log[2]->value; // $u2->id
	
?&gt;
</pre>




<h2>Change log item</h2>
For each change one entry of this object is created. <br />
You can extend this class to create more advanced logging. 
For example log also user who was logged in at the moment.
<pre class="code">
&lt;?php
class DomArChangeLogItem extends DomArObject {
	
	/**
	 * @orm char(15)
	 */
	public $ip;
	/**
	 * @orm plugin DomArDateTime(now)
	 */
	public $datetime;
	/**
	 * @orm int(11)
	 */
	public $objectId;
	/**
	 * @orm char(255)
	 */
	public $objectClassName;
	/**
	 * @orm char(255)
	 */
	public $propertyName;
	/**
	 * @orm char(50000)
	 */
	public $value;
	
	/**
	 * Prepare log item. Use this method for setting custom properties like logged in user id...
	 */
	public function prepare( DomArObject $object ) {
		
	}
	/**
	 * Prepare object old property value for storage.
	 *
	 * @param DomArObject $object
	 * @param Mixed $oldPropertyValue
	 * @return String
	 */
	public function parseValue( DomArObject $object, &$oldPropertyValue ) {
		$set = new DomArValueSet();
		$object->getProperty( $this->propertyName )->update( $object, $oldPropertyValue, $set );
		$values = $set->getValues();
		
		// try to escape mysql query params
		foreach( $values as &$value ) {
			if( $value == 'NULL')
				$value = NULL;
			else if( $value[0] == '\'' && substr($value,-1,1) == '\'')
				$value = substr($value,1,-1);
			else
				$value = (string)$value;
		}
		
		return $value;
	}
	
}
?&gt;
</pre>
{/literal}